Aws
Auth
Axios
Admin
Angular
Android
Atom Payment
BPO
BcryptJs
Bootstrap
Basic Computer
C Language
C++
Css
Canva
Common questions
CorelDraw
Cloudinary
Content Writer
DSA
Django
Error
Excel
ExpressJs
Flutter
Github
Graphql
GoDaddy
HR
Html5
Hostinger
Jwt
Java
Json
Jquery
Javascript
Linux OS
Loopback API
MySQL
Manager
MongoDB
Marketing
MS Office
Mongoose
NodeJs
NextJs
Php
Python
Photoshop
PostgreSQL
PayU Payment
Paypal Payment
Redux
ReactJs
Router
React Native
React Router Dom
React Helmet
Sass
SEO
SMO
Stripe Payment
System Administrator
Software Testing
Typescript
Tailwind
Telesales
Tally
VueJs
Windows OS
XML
Description : `from` creates a new array instance from an array-like or iterable object.
`Array.prototype.from` creates a new array instance from an array-like or iterable object. It can also take a map function to modify the elements while creating the new array. const arrLike = { length: 3, 0: 'a', 1: 'b', 2: 'c' }; const arr = Array.from(arrLike); console.log(arr); // ['a', 'b', 'c']
Category : Javascript
Created Date : 9/6/2024
What is the `Array.prototype.isArray` method in JavaScript?
`Array.isArray` determines whether a value is an array. It returns `true` if the value is an array, otherwise `false`. console.log(Array.isArray([1, 2, 3])); // true console.log(Array.isArray({})); // false
`Array.isArray` determines whether a value is an array. It returns `true` if the value is an array, otherwise `false`. console.log(Array.isArray([1, 2, 3])); // true console.log(Array.isArray({})); // false
What is the `Array.prototype.toString` method in JavaScript?
`Array.prototype.toString` returns a string representation of the array by concatenating its elements with commas. It does not modify the original array. const arr = [1, 2, 3]; console.log(arr.toString()); // '1,2,3'
`Array.prototype.toString` returns a string representation of the array by concatenating its elements with commas. It does not modify the original array. const arr = [1, 2, 3]; console.log(arr.toString()); // '1,2,3'
What is the `String.prototype.toUpperCase` method in JavaScript?
`String.prototype.toUpperCase` returns a new string with all characters converted to uppercase. const str = 'hello'; const upper = str.toUpperCase(); console.log(upper); // 'HELLO'
`String.prototype.toUpperCase` returns a new string with all characters converted to uppercase. const str = 'hello'; const upper = str.toUpperCase(); console.log(upper); // 'HELLO'
What is the `String.prototype.replace` method in JavaScript?
`String.prototype.replace` replaces the first occurrence of a substring or pattern (regular expression) with a new substring. To replace all occurrences, a global regular expression must be used. const str = 'hello world'; const newStr = str.replace('world', 'JavaScript'); console.log(newStr); // 'hello JavaScript'
`String.prototype.replace` replaces the first occurrence of a substring or pattern (regular expression) with a new substring. To replace all occurrences, a global regular expression must be used. const str = 'hello world'; const newStr = str.replace('world', 'JavaScript'); console.log(newStr); // 'hello JavaScript'
What is the `String.prototype.includes` method in JavaScript?
`String.prototype.includes` checks if a string contains a specified substring. It returns `true` if the substring is found, otherwise `false`. const str = 'hello'; console.log(str.includes('ell')); // true console.log(str.includes('world')); // false
`String.prototype.includes` checks if a string contains a specified substring. It returns `true` if the substring is found, otherwise `false`. const str = 'hello'; console.log(str.includes('ell')); // true console.log(str.includes('world')); // false
What is the `String.prototype.concat` method in JavaScript?
`String.prototype.concat` combines multiple strings into one string. It does not modify the original strings but returns a new concatenated string. const str1 = 'hello'; const str2 = 'world'; const combined = str1.concat(' ', str2); console.log(combined); // 'hello world'
`String.prototype.concat` combines multiple strings into one string. It does not modify the original strings but returns a new concatenated string. const str1 = 'hello'; const str2 = 'world'; const combined = str1.concat(' ', str2); console.log(combined); // 'hello world'
What is the `String.prototype.substr` method in JavaScript?
`String.prototype.substr` extracts a substring from a string based on a starting index and length. It returns the extracted substring. const str = 'hello world'; const substr = str.substr(6, 5); console.log(substr); // 'world'
`String.prototype.substr` extracts a substring from a string based on a starting index and length. It returns the extracted substring. const str = 'hello world'; const substr = str.substr(6, 5); console.log(substr); // 'world'
What is the `Array.prototype.find` method in JavaScript?
`Array.prototype.find` returns the first element in the array that satisfies the provided testing function. If no elements satisfy the function, it returns `undefined`. It does not modify the original array. const arr = [1, 2, 3]; const firstEven = arr.find(num => num % 2 === 0); console.log(firstEven); // 2
`Array.prototype.find` returns the first element in the array that satisfies the provided testing function. If no elements satisfy the function, it returns `undefined`. It does not modify the original array. const arr = [1, 2, 3]; const firstEven = arr.find(num => num % 2 === 0); console.log(firstEven); // 2
What is the `Array.prototype.reduceRight` method in JavaScript?
`Array.prototype.reduceRight` executes a reducer function on each element of the array from right to left, accumulating a single result. It is similar to `reduce`, but processes elements in reverse order. const arr = [1, 2, 3]; const result = arr.reduceRight((acc, num) => acc + num, 0); console.log(result); // 6
`Array.prototype.reduceRight` executes a reducer function on each element of the array from right to left, accumulating a single result. It is similar to `reduce`, but processes elements in reverse order. const arr = [1, 2, 3]; const result = arr.reduceRight((acc, num) => acc + num, 0); console.log(result); // 6
What is the `Array.prototype.entries` method in JavaScript?
`Array.prototype.entries` returns a new Array Iterator object that contains the key/value pairs for each index in the array. It allows iteration over the array's indices and values. const arr = ['a', 'b', 'c']; const iterator = arr.entries(); for (const [index, element] of iterator) { console.log(index, element); } // Output: // 0 'a' // 1 'b' // 2 'c'
`Array.prototype.entries` returns a new Array Iterator object that contains the key/value pairs for each index in the array. It allows iteration over the array's indices and values. const arr = ['a', 'b', 'c']; const iterator = arr.entries(); for (const [index, element] of iterator) { console.log(index, element); } // Output: // 0 'a' // 1 'b' // 2 'c'
What is the `String.prototype.slice` method in JavaScript?
`String.prototype.slice` extracts a section of a string and returns it as a new string, without modifying the original string. const str = 'hello'; const sliced = str.slice(1, 4); console.log(sliced); // 'ell'
`String.prototype.slice` extracts a section of a string and returns it as a new string, without modifying the original string. const str = 'hello'; const sliced = str.slice(1, 4); console.log(sliced); // 'ell'
What is the `String.prototype.endsWith` method in JavaScript?
`String.prototype.endsWith` checks if a string ends with a specified substring and returns `true` if it does, otherwise `false`. const str = 'hello'; console.log(str.endsWith('lo')); // true console.log(str.endsWith('he')); // false
`String.prototype.endsWith` checks if a string ends with a specified substring and returns `true` if it does, otherwise `false`. const str = 'hello'; console.log(str.endsWith('lo')); // true console.log(str.endsWith('he')); // false
What is the `String.prototype.link` method in JavaScript?
`String.prototype.link` creates an HTML `<a>` element wrapping the string, which is used to create hyperlinks. This method is deprecated and should not be used in modern applications. const str = 'Click here'; const linkedStr = str.link('https://example.com'); console.log(linkedStr); // '<a href="https://example.com">Click here</a>'
`String.prototype.link` creates an HTML `<a>` element wrapping the string, which is used to create hyperlinks. This method is deprecated and should not be used in modern applications. const str = 'Click here'; const linkedStr = str.link('https://example.com'); console.log(linkedStr); // '<a href="https://example.com">Click here</a>'
What is the `Array.prototype.shift` method in JavaScript?
`Array.prototype.shift` removes the first element from an array and returns that element. It modifies the original array and shifts all subsequent elements down by one. const arr = [1, 2, 3]; const first = arr.shift(); console.log(first); // 1 console.log(arr); // [2, 3]
`Array.prototype.shift` removes the first element from an array and returns that element. It modifies the original array and shifts all subsequent elements down by one. const arr = [1, 2, 3]; const first = arr.shift(); console.log(first); // 1 console.log(arr); // [2, 3]
What is the `Array.prototype.values` method in JavaScript?
`Array.prototype.values` returns a new Array Iterator object that contains the values for each index in the array. It allows iteration over the array's values. const arr = ['a', 'b', 'c']; const iterator = arr.values(); for (const value of iterator) { console.log(value); } // Output: // 'a' // 'b' // 'c'
`Array.prototype.values` returns a new Array Iterator object that contains the values for each index in the array. It allows iteration over the array's values. const arr = ['a', 'b', 'c']; const iterator = arr.values(); for (const value of iterator) { console.log(value); } // Output: // 'a' // 'b' // 'c'
What is the `Array.prototype.filter` method in JavaScript?
`Array.prototype.filter` creates a new array with all elements that pass a provided test function. It does not modify the original array. const arr = [1, 2, 3, 4]; const evens = arr.filter(num => num % 2 === 0); console.log(evens); // [2, 4]
`Array.prototype.filter` creates a new array with all elements that pass a provided test function. It does not modify the original array. const arr = [1, 2, 3, 4]; const evens = arr.filter(num => num % 2 === 0); console.log(evens); // [2, 4]
What is the `Array.prototype.splice` method in JavaScript?
`Array.prototype.splice` changes the contents of an array by removing or replacing existing elements and/or adding new elements in place. It modifies the original array and returns an array containing the removed elements. const arr = [1, 2, 3, 4]; const removed = arr.splice(1, 2, 'a', 'b'); console.log(arr); // [1, 'a', 'b', 4] console.log(removed); // [2, 3]
`Array.prototype.splice` changes the contents of an array by removing or replacing existing elements and/or adding new elements in place. It modifies the original array and returns an array containing the removed elements. const arr = [1, 2, 3, 4]; const removed = arr.splice(1, 2, 'a', 'b'); console.log(arr); // [1, 'a', 'b', 4] console.log(removed); // [2, 3]
What is the `Array.prototype.sort` method in JavaScript?
`Array.prototype.sort` sorts the elements of an array in place and returns the sorted array. By default, elements are sorted as strings. A custom sorting function can be used to specify the sort order. const arr = [3, 1, 2]; arr.sort((a, b) => a - b); console.log(arr); // [1, 2, 3]
`Array.prototype.sort` sorts the elements of an array in place and returns the sorted array. By default, elements are sorted as strings. A custom sorting function can be used to specify the sort order. const arr = [3, 1, 2]; arr.sort((a, b) => a - b); console.log(arr); // [1, 2, 3]
What is the `String.prototype.fromCharCode` method in JavaScript?
`String.fromCharCode` returns a string created from the specified sequence of UTF-16 code units. It is used to convert code units to characters. const char = String.fromCharCode(65); console.log(char); // 'A'
`String.fromCharCode` returns a string created from the specified sequence of UTF-16 code units. It is used to convert code units to characters. const char = String.fromCharCode(65); console.log(char); // 'A'
What is the `String.prototype.startsWith` method in JavaScript?
`String.prototype.startsWith` checks if a string starts with a specified substring and returns `true` if it does, otherwise `false`. const str = 'hello'; console.log(str.startsWith('he')); // true console.log(str.startsWith('lo')); // false
`String.prototype.startsWith` checks if a string starts with a specified substring and returns `true` if it does, otherwise `false`. const str = 'hello'; console.log(str.startsWith('he')); // true console.log(str.startsWith('lo')); // false
What is the `Array.prototype.every` method in JavaScript?
`Array.prototype.every` tests whether all elements in the array pass a provided test function. It returns `true` if all elements pass the test, otherwise `false`. It does not modify the original array. const arr = [2, 4, 6]; const allEven = arr.every(num => num % 2 === 0); console.log(allEven); // true
`Array.prototype.every` tests whether all elements in the array pass a provided test function. It returns `true` if all elements pass the test, otherwise `false`. It does not modify the original array. const arr = [2, 4, 6]; const allEven = arr.every(num => num % 2 === 0); console.log(allEven); // true
What is the `Array.prototype.slice` method in JavaScript?
`Array.prototype.slice` returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included). It does not modify the original array. const arr = [1, 2, 3, 4]; const sliced = arr.slice(1, 3); console.log(sliced); // [2, 3]
`Array.prototype.slice` returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included). It does not modify the original array. const arr = [1, 2, 3, 4]; const sliced = arr.slice(1, 3); console.log(sliced); // [2, 3]
What is the `String.prototype.trim` method in JavaScript?
`String.prototype.trim` removes whitespace from both ends of a string, but does not affect whitespace in the middle of the string. const str = ' hello '; const trimmed = str.trim(); console.log(trimmed); // 'hello'
`String.prototype.trim` removes whitespace from both ends of a string, but does not affect whitespace in the middle of the string. const str = ' hello '; const trimmed = str.trim(); console.log(trimmed); // 'hello'
What is the `String.prototype.charAt` method in JavaScript?
`String.prototype.charAt` returns the character at a specified index in a string. If the index is out of range, it returns an empty string. const str = 'hello'; const char = str.charAt(1); console.log(char); // 'e'
`String.prototype.charAt` returns the character at a specified index in a string. If the index is out of range, it returns an empty string. const str = 'hello'; const char = str.charAt(1); console.log(char); // 'e'
What is the `String.prototype.match` method in JavaScript?
`String.prototype.match` retrieves the matches of a string against a regular expression. It returns an array of matches or `null` if no matches are found. const str = 'hello 123'; const matches = str.match(/\d+/); console.log(matches); // ['123']
`String.prototype.match` retrieves the matches of a string against a regular expression. It returns an array of matches or `null` if no matches are found. const str = 'hello 123'; const matches = str.match(/\d+/); console.log(matches); // ['123']